﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Transport
{
    public class DanhSachXeDatControl
    {
        transportEntities db;

        public DanhSachXeDatControl()
        {
            db = new transportEntities();
        }

        public List<danh_sach_xe_dat> findByReservationID(string ID)
        {
            try
            {
                return db.danh_sach_xe_dat.Where(t => t.ma_so_dat_xe == ID).ToList();
            }
            catch (Exception)
            {
                return null;
            }
        }

        public List<danh_sach_xe_dat> findByCarNumber(string number)
        {
            try
            {
                return db.danh_sach_xe_dat.Where(t => t.bien_so == number).ToList();
            }
            catch (Exception)
            {
                return null;
            }
        }

        public danh_sach_xe_dat find(string id, string carnumber)
        {
            try
            {
                return db.danh_sach_xe_dat.SingleOrDefault(t => t.ma_so_dat_xe == id && t.bien_so == carnumber);
            }
            catch (Exception)
            {
                return null;
            }
        }

        public bool insert(danh_sach_xe_dat value)
        {
            try
            {
                db.danh_sach_xe_dat.AddObject(value);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool update(danh_sach_xe_dat value)
        {
            try
            {
                danh_sach_xe_dat ds = db.danh_sach_xe_dat.SingleOrDefault(t => t.ma_so_dat_xe == value.ma_so_dat_xe && t.bien_so == value.bien_so);
                ds = value;
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public bool delete(string id, string carnumber)
        {
            try
            {
                danh_sach_xe_dat ct = db.danh_sach_xe_dat.SingleOrDefault(t => t.ma_so_dat_xe == id && t.bien_so == carnumber);
                db.danh_sach_xe_dat.DeleteObject(ct);
                db.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
    }
}